package net.xdclass.strategy;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class ShardingDBConfig {

    /**
     * 启用存储数据库位置编号
     */
    private static final List<String> dfPrefix = new ArrayList<>();
//    private static Random random = new Random();

    // 配置启用那些库的前缀
    static {
        dfPrefix.add("0");
        dfPrefix.add("1");
        dfPrefix.add("a");
    }

    /**
     * 获取随机的前缀
     *
     * @return
     */
    public static String getRandomDBPrefix(String code) {
//        int i = random.nextInt(dfPrefix.size());
        int hashCode = code.hashCode();
        int i = Math.abs(hashCode) % dfPrefix.size();
        return dfPrefix.get(i);
    }


}
